from models import QueryOneInstance, Admin, Role,  Personal, Like, Comment, Blog, \
 User, QueryOneRelatedInstance, QueryMultipleRelatedInstances


def PK_UserName(uid):
    return {
        "t_username":QueryOneInstance(User,{'id':uid}).username
    }

def PK_UserInfo(uid):
    user = QueryOneInstance(User,{'id':uid})

    admin = QueryOneRelatedInstance(Admin, {'uid':  uid},user)
    role = QueryOneRelatedInstance(Role, {'uid':  uid},user)
    personal = QueryOneRelatedInstance(Personal, {'uid':  uid},user)

    likes = QueryMultipleRelatedInstances(Like, {'uid':  uid},user)
    comments = QueryMultipleRelatedInstances(Comment, {'uid':  uid},user)
    blogs = QueryMultipleRelatedInstances(Blog, {'uid':  uid, 'checked': True, 'passed': True},user)

    return {
        "b_admin": admin is not None,

        "t_uid":user.id,
        "t_username": user.username,
        "t_role": role.role,
        "t_part": role.part,
        "t_intro": personal.intro,

        "i_icon": personal.img_icon,
        "i_background": personal.img_background,

        "s_post_passed": len(blogs),
        "s_post_get_like": len(likes),
        "s_comment": len(comments),
    }